1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import UIKit
import AVFoundation
class ViewController: UIViewController{
var btnSound: AVAudioPlayer!
override func viewDidLoad() {
super.viewDidLoad()
let path = NSBundle.mainBundle().pathForResource("btn", ofType: "wav")
let soundUrl = NSURL(fileURLWithPath: path!)
do {
try btnSound = AVAudioPlayer(contentsOfURL: soundUrl)
btnSound.prepareToPlay()
} catch {
}
}
...

Reference: How to play sounds using AVAudioPlayer

Prev Next